/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License. You may obtain a copy of the License at
	http://www.mozilla.org/MPL/
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import fever.app.local.Localisation;
import fever.app.local.LocalisationEvent;
import fever.core.Resources;

/**
 * {@code ValidationResources } class.
 *
 * @author Romain Ecarnot
 */
class fever.data.validators.ValidationResources extends Resources
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private static var _instance : ValidationResources;
	
	
	//-------------------------------------------------------------------------
	// Public Properties
	//-------------------------------------------------------------------------
	
	public var required_field_error : String;
		
	public var string_too_long_error : String;
	public var string_too_short_error : String;
	public var string_not_contain_error : String;
	
	public var number_decimal_counter_error : String;
	public var number_separator_error : String;
	public var number_invalid_char_error : String;
	public var number_negative_error : String;
	public var number_integer_error : String;
	public var number_exceed_max_error : String;
	public var number_lower_than_min_error : String;
	public var number_precision_error : String;
	
	public var mail_missing_at_sign_error : String;
	public var mail_too_many_at_sign_error : String;
	public var mail_invalid_domain_error : String;
	public var mail_missing_username_error : String;
	public var mail_invalid_char_error : String;
	public var mail_invalid_email_error : String;
	
	public var argumentes_exceed_max_error : String;
	public var arguments_lower_than_min_error : String;
	public var arguments_undefined_found_error : String;
		public var range_minimum : String;	public var range_maximum : String;
	
	public var password_tips : String;
	public var password_number : String;
	public var password_lower : String;
	public var password_upper : String;
	public var password_special : String;
	public var password_special_chars : Array;
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Returns {@link ValidationResources} instance.
	 * 
	 * <p>Always returns the same instance.<br />
	 * Design Pattern Singleton.
	 * @return {@link ValidationResources} instance
	 */
	public static function getInstance() : ValidationResources
	{
		if( !_instance ) _instance = new ValidationResources();
		return _instance;	
	}
	
	/** 
	 * Triggered when Localisation language change.
	 */
	public function onLocalisationUpdate(event : LocalisationEvent ) : Void
	{
		required_field_error = Localisation.getResource( 'fever:validation.required_field_error' );
		
		string_too_long_error = Localisation.getResource( 'fever:validation.string_too_long_error' );
		string_too_short_error = Localisation.getResource( 'fever:validation.string_too_short_error' );
		string_not_contain_error = Localisation.getResource( 'fever:validation.string_not_contain_error' );
		
		number_decimal_counter_error = Localisation.getResource( 'fever:validation.number_decimal_counter_error' );
		number_separator_error = Localisation.getResource( 'fever:validation.number_separator_error' );
		number_invalid_char_error = Localisation.getResource( 'fever:validation.number_invalid_char_error' );
		number_negative_error = Localisation.getResource( 'fever:validation.number_negative_error' );
		number_integer_error = Localisation.getResource( 'fever:validation.number_integer_error' );
		number_exceed_max_error = Localisation.getResource( 'fever:validation.number_exceed_max_error' );
		number_lower_than_min_error = Localisation.getResource( 'fever:validation.number_lower_than_min_error' );
		number_precision_error = Localisation.getResource( 'fever:validation.number_precision_error');
		
		mail_missing_at_sign_error = Localisation.getResource( 'fever:validation.mail_missing_at_sign_error' );
		mail_too_many_at_sign_error = Localisation.getResource( 'fever:validation.mail_too_many_at_sign_error' );
		mail_invalid_domain_error = Localisation.getResource( 'fever:validation.mail_invalid_domain_error' );
		mail_missing_username_error = Localisation.getResource( 'fever:validation.mail_missing_username_error' );
		mail_invalid_char_error = Localisation.getResource( 'fever:validation.mail_invalid_char_error' );
		mail_invalid_email_error = Localisation.getResource( 'fever:validation.mail_invalid_email_error' );
		
		argumentes_exceed_max_error = Localisation.getResource( 'fever:validation.argumentes_exceed_max_error' );
		arguments_lower_than_min_error = Localisation.getResource( 'fever:validation.arguments_lower_than_min_error' );
		arguments_undefined_found_error = Localisation.getResource( 'fever:validation.arguments_undefined_found_error' );
		
		range_minimum = Localisation.getResource( 'fever:validation.range_minimum' );
		range_maximum = Localisation.getResource( 'fever:validation.range_maximum' );
		
		password_tips = Localisation.getResource( 'fever:validation.password_tips' );
		password_number = Localisation.getResource( 'fever:validation.password_number' );
		password_lower = Localisation.getResource( 'fever:validation.password_lower' );
		password_upper = Localisation.getResource( 'fever:validation.password_upper' );
		password_special = Localisation.getResource( 'fever:validation.password_special' );
		password_special_chars = String( Localisation.getResource( 'fever:validation.password_special_chars' ) ).split('');
	}
	
	
	//-------------------------------------------------------------------------
	// Private implementation
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	private function ValidationResources()
	{
		super( 'fever:validation' );
	}	
	
	private function _initDefault() : Void
	{
		required_field_error = 'The field is required';
		
		string_too_long_error = 'This String is longer than the maximum allowed length';
		string_too_short_error = 'This String is shorter than the minimum allowed length';
		string_not_contain_error = 'This String not contain defined substring';
		
		number_decimal_counter_error = 'The decimal separator can occur only once';
		number_separator_error = 'Invalid characters in your email address';
		number_invalid_char_error = 'The input contains invalid characters';
		number_negative_error = 'The number may not be negative';
		number_integer_error = 'The number must be an integer';
		number_exceed_max_error = 'The number entered is too large';
		number_lower_than_min_error = 'The number entered is too small';
		number_precision_error = 'The number entered has too many digits beyond the decimal point';
		
		mail_missing_at_sign_error = 'Missing an \'@\' character in your email address';
		mail_too_many_at_sign_error = 'Too many \'@\' characters in your email address';
		mail_invalid_domain_error = 'The domain in your email address is incorrect';
		mail_missing_username_error = 'The username in your email address is missing';
		mail_invalid_char_error = 'Invalid characters in your email address';
		mail_invalid_email_error = 'This email is not correct';
		
		argumentes_exceed_max_error = 'The length of arguments is too large';
		arguments_lower_than_min_error = 'The length of arguments is too small';
		arguments_undefined_found_error = 'One of arguments is undefined';
		
		range_minimum = 'Should select at least %1 option(s).';
		range_maximum = 'Should select %1 option(s) at most.';
		
		password_tips = 'Password should contain';
		password_number = 'numbers';
		password_lower = 'lowercase chars';
		password_upper = 'uppercase chars';
		password_special = 'special chars';
		password_special_chars = new Array( "+", "&", "\"", "'", "(", "[", "-", "|", "_", "^", ")", "]", "¨", "$", "£", "*", "µ", "ù", "§", "!", ":", "/", ";", ".", ",", "?","{", "}" );
	}

}